package com.ftg.learn.day10.factory;

import lombok.Data;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * 大象
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/8/11 下午1:56
 */
public class Elephant {

    private String name = "fdsfsdfdsfdsfaaa";

    private String color;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public static void main(String[] args) throws InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {

        String[] methodsName = new String[15];
        Class c1 = Elephant.class;
        Method[] methods = c1.getDeclaredMethods();
        int j = 0;
        for (Method method : methods) {
            methodsName[j++] =  method.getName();
        }

        Method getNameMethod = c1.getMethod("getName");

        Object obj = c1.newInstance();
        //invoke 执行(哪一个实例,参数)
        String name = getNameMethod.invoke(obj).toString();
        System.out.println(name);

        System.out.println(Arrays.toString(methods));

        //Class
        //field 字段
//        Class c1 = Elephant.class;
//        String[] str = new String[2];
//
//        Object o = c1.newInstance();
//
//        Field[] declaredFields = c1.getDeclaredFields();
//
//        //遍历 增强型 for
//        int i = 0;
//        for (Field x : declaredFields) {
//            System.out.println(x.getName()+"字段名称");
//            str[i++] = x.getName();
//
////            实例。字段 = 値；
//            if (x.getName().equals("name")) {
//                x.set(o,"张三丰");
//            }else{
//                x.set(o,"紫袍");
//                System.out.println(x.get(o));
//            }
//
////            实例。字段 = 値；
////            实例。字段 = 値；
////            实例。字段 = 値；
//        }
//        System.out.println(o);
//
//        System.out.println(Arrays.toString(str));

    }

}
